package com.sl.au.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import com.sl.au.entity.InventoryDetail;
import com.sl.au.service.InventoryDetailService;

@RestController
@RequestMapping(value="/ui/inventoryDetail")
public class InventoryDetailController extends BaseController {

	@Autowired
	InventoryDetailService inventoryDetailService;
	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView index(){
		ModelAndView modelAndView = createLayoutView("inventoryDetail/inventoryDetailindex");
	return modelAndView;
	}
	
	//获得外贸价格单的列表
	@RequestMapping(value="/getpage",method = RequestMethod.GET)
	public Map<String, Object> getPage(HttpServletRequest request){
		Map<String, Object> map=new HashMap<String, Object>();
		int start = Integer.parseInt(request.getParameter("start"));
		int length = Integer.parseInt(request.getParameter("length"));
		long count=0;
		String key=request.getParameter("key");
		List<InventoryDetail> inventoryDetails = inventoryDetailService.getInventoryDetail(start, length, key, null, null);
		if(key==null){
			count=inventoryDetailService.getRepository().count();
		}
		if(key!=null){
		count=inventoryDetailService.getRepository().findCount(key);
		}
		map.put("data", inventoryDetails);
		map.put("draw", request.getParameter("draw"));
		map.put("recordsFiltered", count);
		map.put("recordsTotal", count);
		return map;
	}
}
